<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class diagnosis_model extends CI_Model
{
	
	public function __construct()
	{
		parent::__construct();

	}
public function get_view()
	{
	$this->datatables
			->select("customer.id as id,case.case_no,customer.service_date,customer.customer_name,status.name,users.username,customer.mobile,customer.customer_address")
			->from('customer','diagnosis','status','users','case')	
            ->join('diagnosis','customer.service_id=diagnosis.service_id')
			->join('case','case.id=diagnosis.case_id')
            ->join('status','diagnosis.status_id=status.id')	
            ->join('users'	,'diagnosis.enginer_id=users.id')	
			->add_column("Actions",
			"<center>			</center>", "id")
			
			;
	   return  $this->datatables->generate();
	}
	public function nonwarranty_view()
	{
	$this->datatables
			->select("customer.id as id,nonwarranty_case.case_no,customer.service_date,customer.customer_name,status_nonwarranty.name,users.username,customer.mobile,customer.customer_address")
			->from('customer','nonwarranty_diagnosis','status','users','nonwarranty_case')	
            ->join('nonwarranty_diagnosis','customer.service_id=nonwarranty_diagnosis.service_id')
            ->join('status_nonwarranty','nonwarranty_diagnosis.status_id=status_nonwarranty.id')	
            ->join('users'	,'nonwarranty_diagnosis.engineer_id=users.id')
            ->join('nonwarranty_case','nonwarranty_diagnosis.case_id=nonwarranty_case.id')
            ->where('nonwarranty_case.status_id != 21')			
			->add_column("Actions",
			"<center>			</center>", "id")
			
			;
	   return  $this->datatables->generate();
	}
public function get_disp_view()
	{
	$this->datatables
			->select("case.id as id,case.case_no,case.hp_case,diagnosis.date,diagnosis.completion_date,status.name,users.username,customer.customer_name,customer.mobile")
			->from('customer','diagnosis','status','users','case')	
            ->join('diagnosis','customer.service_id=diagnosis.service_id')
			->join('case','diagnosis.case_id=case.id')
            ->join('status','case.status_id=status.id')	
            ->join('users'	,'diagnosis.enginer_id=users.id')	
			->where('diagnosis.status_id',3)
			->add_column("Actions",
			"<center>			<a href='index.php/admin/diagnosis/get_docket/$1'>
								<i class='icon-edit ' title='Collect Docket No.'></i>
								</a>
								
							   </center>", "id")
			
			;
	   return  $this->datatables->generate();
	}
	public function nonwarranty_disp_view()
	{
	$this->datatables
			->select("nonwarranty_case.id as id,nonwarranty_case.case_no,nonwarranty_diagnosis.date,nonwarranty_diagnosis.completion_date,status_nonwarranty.name,users.username,customer.customer_name,customer.mobile")
			->from('customer','nonwarranty_diagnosis','status','users','nonwarranty_case')	
            ->join('nonwarranty_diagnosis','customer.service_id=nonwarranty_diagnosis.service_id')
			->join('nonwarranty_case','nonwarranty_diagnosis.service_id=nonwarranty_case.service_id')
            ->join('status_nonwarranty','nonwarranty_case.status_id=status_nonwarranty.id')	
            ->join('users'	,'nonwarranty_diagnosis.engineer_id=users.id')	
			->where('nonwarranty_case.status_id != 21')
			->where('nonwarranty_diagnosis.status_id',3)
			->add_column("Actions",
			"<center>			<a href='index.php/admin/diagnosis/get_part/$1'>
								<i class='icon-edit ' tilte='Get Order No'></i>
								</a>
								
							   </center>", "id")
			
			;
	   return  $this->datatables->generate();
	}
	public function get_case_n($id)
	{
	
	$query = $this->db->get_where('case', array('id' => $id));
		return $query;
	
	
	}
public function nonwarranty_case_n($id)
	{
	
	$query = $this->db->get_where('nonwarranty_case', array('id' => $id));
		return $query;
	
	
	}	
	public function enter_docket($insert)
	{
	$this->db->insert('dispatch',$insert);
	
	}
public function update_case_status($id)
{
$insert=array('status_id'=>21,);
$this->db->update('case',$insert,array('id'=>$id));

}	
public function get_docket_detail($id)
{

$query = $this->db->get_where('dispatch', array('case_id' => $id));
		return $query;
}
public function get_part_detail($id)
{

$query = $this->db->get_where('nonwarranty_part', array('case_id' => $id));
		return $query->result();
}

public function get_max_order()
{
	$this->db->select_max('id');
    return $this->db->get('nonwarranty_order');

}
public function create_supplier($insert)
{

$this->db->insert('part_supplier',$insert);

}
public function get_supplier()
{
$query= $this->db->get('part_supplier');
	return $query->result();

}
public function supplier_view()
{

	$this->datatables
			->select("id,name,email,mobile,landline,address")
			->from('part_supplier')	
			->add_column("Actions",
			"<center>			
			<a href='index.php/admin/diagnosis/edit_supplier/$1'>
								<i class='icon-edit '></i>
								</a>
			 <a href='index.php/admin/diagnosis/delete_supplier/$1' onClick=\"return confirm('You are going to delete Supplier id:$1')\">
								<i class='icon-trash '></i>
			</center>", "id");
	   return  $this->datatables->generate();
}
public function get_supplier_detail($id)
{
$query = $this->db->get_where('part_supplier', array('id' => $id));
		return $query;
}
public function update_supplier($insert,$id)
{
$this->db->update('part_supplier',$insert,array('id'=>$id));
}	
public function delete_supplier($id)
{
$this->db->delete('part_supplier',array('id'=>$id));		
}
public function chk_order($id)
{
$query = $this->db->get_where('nonwarranty_order', array('case_id' => $id));
		return $query;

}
public function get_email($case)
{
$this->db->select('customer.email');
	$this->db->from('customer', 'case' );
	$this->db->join('case', 'customer.service_id= case.service_id');
	$this->db->where('case.id',$case);
	$q = $this->db->get();
  return $q;
}
public function get_company()
{
	return $this->db->get('company_profile');

}
public function get_view_admin($id)
	{
	$this->datatables
			->select("customer.id as id,case.case_no,diagnosis.date,status.name,customer.customer_name,customer.mobile")
			->from('diagnosis','customer','users','status','case')
			->join('case','case.id=diagnosis.case_id')
			->join('customer','customer.service_id=diagnosis.service_id')
			->join('users','users.id=diagnosis.enginer_id')
			->join('status','diagnosis.status_id=status.id')
			->where('users.id',$id)
			->where('diagnosis.status_id',1)
		    ->add_column("Actions",
			"<center>		
								<a href='index.php/engineer/diagnosis/view_detail/$1'>
								<i class='icon-edit 'title='View Detail'></i>
								</a>
								</center>", "id")
			
			;
	   return  $this->datatables->generate();
	}
	public function nonwarranty_view_admin($id)
	{
	$this->datatables
			->select("customer.id as id, nonwarranty_case.case_no,nonwarranty_diagnosis.date,status.name,customer.customer_name,customer.mobile")
			->from('nonwarranty_diagnosis','customer','users','status','nonwarranty_case')
			->join('customer','customer.service_id=nonwarranty_diagnosis.service_id')
			->join('users','users.id=nonwarranty_diagnosis.engineer_id')
			->join('status','nonwarranty_diagnosis.status_id=status.id')
			->join('nonwarranty_case','nonwarranty_case.service_id=nonwarranty_diagnosis.service_id')
			->where('nonwarranty_case.status_id != 21')
			->where('users.id',$id)
			->where('nonwarranty_diagnosis.status_id',1)
		    ->add_column("Actions",
			"<center>		
								<a href='index.php/engineer/diagnosis/view_detail/$1'>
								<i class='icon-edit'title='View Detail'></i>
								</a>
								</center>", "id")
			
			;
	   return  $this->datatables->generate();
	}
public function get_current_view($id)
	{
	$this->datatables
			->select("customer.id as id, case.case_no,case.date,status.name,customer.customer_name,customer.mobile")
			->from('customer','diagnosis','users','status','case')
			->join('diagnosis','customer.service_id=diagnosis.service_id')
			->join('users','users.id=diagnosis.enginer_id')
			->join('status','diagnosis.status_id=status.id')
			->join('case','diagnosis.case_id=case.id')
			->where('diagnosis.status_id = 2')
			->where('users.id',$id)
			
		    ->add_column("Actions",
			"<center>		
								<a href='index.php/engineer/diagnosis/dispatch_detail/$1'>
								<i class='icon-edit '></i>
								</a>
								</center>", "id")
			
			;
	   return  $this->datatables->generate();
	}
	public function nonwarranty_current_view_admin($id)
	{
	$this->datatables
			->select("customer.id as id, nonwarranty_case.case_no,nonwarranty_case.date,status.name,customer.customer_name,customer.mobile")
			->from('nonwarranty_diagnosis','customer','users','status')
			->join('customer','customer.service_id=nonwarranty_diagnosis.service_id')
			->join('users','users.id=nonwarranty_diagnosis.engineer_id')
			->join('status','nonwarranty_diagnosis.status_id=status.id')
			->join('nonwarranty_case','nonwarranty_diagnosis.service_id=nonwarranty_case.service_id')
			->where('users.id',$id)
			->where('nonwarranty_diagnosis.status_id',2)
			->where('nonwarranty_case.status_id != 21')
		    ->add_column("Actions",
			"<center>		
								<a href='index.php/engineer/diagnosis/nonwarranty_dispatch_detail/$1'>
								<i class='icon-edit '></i>
								</a>
								</center>", "id")
			
			;
	   return  $this->datatables->generate();
	}
public function get_dispatch_view_admin($id)
	{
	$this->datatables
			->select("case.id as id, case.case_no,case.date,status.name,customer.customer_name,customer.mobile")
			->from('diagnosis','customer','users','status')
			->join('customer','customer.service_id=diagnosis.service_id')
			->join('users','users.id=diagnosis.enginer_id')
			->join('status','diagnosis.status_id=status.id')
			->join('case','diagnosis.case_id=case.id')
			->where('users.id',$id)
			->where('diagnosis.status_id',3)
		    ->add_column("Actions",
			"<center>		
								<a href='index.php/engineer/diagnosis/dispatch_detail_view/$1'>
								<i class='icon-edit '></i>
								</a>
								</center>", "id")
			
			;
	   return  $this->datatables->generate();
	}
	public function nonwarranty_dispatch_view_admin($id)
	{
	$this->datatables
			->select("nonwarranty_case.id as id, nonwarranty_case.case_no,nonwarranty_case.date,status.name,customer.customer_name,customer.mobile")
			->from('nonwarranty_diagnosis','customer','users','status','nonwarranty_case')
			->join('customer','customer.service_id=nonwarranty_diagnosis.service_id')
			->join('users','users.id=nonwarranty_diagnosis.engineer_id')
			->join('status','nonwarranty_diagnosis.status_id=status.id')
			->join('nonwarranty_case','nonwarranty_diagnosis.service_id=nonwarranty_case.service_id')
			->where('users.id',$id)
			->where('nonwarranty_diagnosis.status_id',3)
			->where('nonwarranty_case.status_id != 21')
		    ->add_column("Actions",
			"<center>		
								<a href='index.php/engineer/diagnosis/dispatch_detail_nonwarranty/$1'>
								<i class='icon-edit '></i>
								</a>
								</center>", "id")
			
			;
	   return  $this->datatables->generate();
	}

}